<?php
	include_once "DBProperties.php";
	
	$goodTrafficSpeed = 120;//km/h
	$goodTrafficSpeed = $goodTrafficSpeed/3.6; //metres per second
	
	function populatePointArrays($boundLeft,$boundRight,$boundTop,$boundBottom)
	{
		global $databaseName, $connection, $point;
		mysql_select_db($databaseName, $connection);
		$sqlString = "SELECT * FROM ". $point ." WHERE Latitude BETWEEN ".$boundLeft." AND ". $boundRight ." AND Longitude BETWEEN ". $boundBottom." AND ".$boundTop."";

		$results = mysql_query($sqlString);
		
		$string = "";
		
		if ($results == null)
		{
			echo("Not valid");
			return;
		}
		
		while ($row = mysql_fetch_array($results))
		{	 
			$string = $string . $row['Latitude']." ". $row['Longitude'] ." ". $row['Bearing'] ." ". getColour($row['Speed']).' '.$row['Speed'].";";
		}
		return $string;
		
	}
	
	function getColour($speed)
	{
		if($speed > 16)
			return "008000"; //green for great traffic
		
		if($speed > 12)
			return "0000FF";//blue for good traffic
		
		if($speed > 8)
			return "A000FF"; //purple for light traffic	
		
		if($speed > 4)
			return "FF00A0"; //pink for bad traffic
		
		return "FF0000"; //red for terrible traffic 		
	}

	// function getColour($speed)
	// {
		// global $goodTrafficSpeed;
		// $interval = (int)($goodTrafficSpeed/5);
		// $goodTrafficSpeed = (int)($goodTrafficSpeed);
		
		// if($speed >= ($goodTrafficSpeed))
			// return "008000"; //green for great traffic
		// if($speed >= ($goodTrafficSpeed - $interval))
			// return "00FF00"; //lime green for good traffic
		// if($speed >= ($goodTrafficSpeed - 2 * $interval))
			// return "FFFF11"; //yellow for light traffic	
		// if($speed >= ($goodTrafficSpeed - 3 * $interval))
			// return "F5AE07"; //yellow orange for medium traffic
		// if($speed >= ($goodTrafficSpeed - 4 * $interval))
			// return "F2500B"; //dark orange for bad traffic
		// if($speed >= 0)
			// return "FF0000"; //red for terrible traffic 		
	// }
?>